#1.loan-server, loan-client上传到/root下
#2.loan.sql也放到/root下
#3.执行以下命令

#安装node nginx
# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/epel/epel-release-latest-7.noarch.rpm
yum install -y epel-release
yum install -y lrzsz nodejs nginx wget git golang gcc-c++.x86_64 net-tools vim
yum install -y certbot python2-certbot-nginx

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install --upgrade --force-reinstall 'requests==2.6.0'

#升级node到10.15.3
npm i -g n
n v13.11.0
ln -sf /usr/local/bin/node /usr/bin/node
ln -sf /usr/local/bin/npm /usr/bin/npm

#安装cnpm
npm install pm2 -g
npm rebuild node-sass

#建立前端页面目录
mkdir -p /www/wwwlogs /www/wwwroot/loan

#安装mysql
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
yum install  -y  mysql-community-server

#打开mysql事件
echo event_scheduler=ON >> /etc/my.cnf
echo lower_case_table_names=1 >> /etc/my.cnf
service mysqld restart

#获取MySQL的临时密码并修改密码, 并从文件导入表结构
MYSQLPASS=`grep 'temporary password' /var/log/mysqld.log|awk -F"host:" '{print $2}'| sed -e 's/^[ \t]*//g'`
mysql --connect-expired-password -uroot -p$MYSQLPASS <<EOF
  set global validate_password_policy=0;
  set global validate_password_length=1;
  ALTER USER 'root'@'localhost' IDENTIFIED BY 'db123456';
  CREATE DATABASE `loan` DEFAULT CHARACTER SET utf8mb4;
  use loan;
  source loan.sql;
  truncate ViewRecord;
  truncate ApplyRecord;
  truncate ChannelDailyDownStat;
  truncate ChannelDailyStat;
  truncate ChannelUser;
  truncate DailyStat;
  truncate ProductDailyStat;
  truncate SmsLog;
  truncate User;
  truncate ViewRecord;
  truncate loan_channel_daily_stat;
  truncate loan_dc_daily_stat;
  truncate loan_dc_login_log;
  truncate loan_dc_view_log;
  truncate loan_product_daily_stat;
  truncate loan_product_view_log;
  truncate pay_order;
EOF

# 编译loan-admin并初始化数据库
cd ../loan-admin
go env -w GOPROXY=https://goproxy.io,direct
go build

# 运行loan-server
cd ../loan-server
sh start.sh

# 编译loan-client
cd ../loan-client/script
# 下面按照自己的配置，Domain填写自己的域名
sh replace.sh http:// Domain
sh build.sh loan-admin
sh build.sh loan-app
sh build.sh loan-h5
sh build.sh loan-sub-admin

#安装loan-client
cd build
tar zxf out.tgz -C /www/wwwroot/loan

#最后把nginx配置好启动(修改自己的域名)
cd ../../../loan-server/
cp -f loan.conf /etc/nginx/conf.d/
cp -f nginx.conf /etc/nginx/
nginx
